//
//  selectView.m
//  jiajiao
//
//  Created by apple on 16/3/18.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "selectView.h"
#import "selectButten.h"
@interface selectView()
@property(nonatomic,strong)selectButten *butten;
@property(nonatomic,strong)UIView *lineview;
@end
@implementation selectView

-(void)gaveMestringArray:(NSArray*)array
{
    
    self.backgroundColor = [UIColor whiteColor];
    for (NSInteger i=0; i<array.count; i++) {
        selectButten *butten =[[selectButten alloc]init];
        
        CGFloat btnX = (self.frame.size.width/array.count+0.5*Kscr)*i;
        
        CGFloat btnY = 0;
        
        CGFloat btnW =(self.frame.size.width-0.5*Kscr*(array.count-1))/array.count;
        
        CGFloat btnH = self.frame.size.height ;
        
        [butten addTarget:self action:@selector(witchBtnClic:) forControlEvents:UIControlEventTouchUpInside];
        
        [butten setTitle:array[i] forState:UIControlStateNormal];
        [butten setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [butten setTitleColor:knavcolor forState:UIControlStateSelected];
        butten.tag = i;
        butten.backgroundColor = [UIColor whiteColor];
        butten.frame = CGRectMake(btnX, btnY, btnW, btnH);
        [self addSubview:butten];
        if (butten.tag==0) {
            [self witchBtnClic:butten];
        }

        [self lineView:array];
        
        

    }
    
}
-(void)lineView:(NSArray *)array
{
    for (NSInteger i=0; i<array.count; i++) {
        
        if (i==0) {
        }else
        {
            UIView *lineview = [[UIView alloc]init];
            
            CGFloat lineviewX = ((self.frame.size.width-0.5*(array.count))/array.count)*i;
            CGFloat lineviewY = (self.frame.size.height-20)/2;
            CGFloat lineviewW = 0.5*Kscr;
            CGFloat lineviewH = 20*Kscr;
            
            lineview.backgroundColor = klineColor;
            lineview.frame = CGRectMake(lineviewX, lineviewY, lineviewW, lineviewH);
            [self addSubview:lineview];

        }
        
    }
}
-(void)witchBtnClic:(selectButten *)btn
{
    if (self.butten!=btn) {
        btn.selected = YES;
        self.butten.selected=NO;
        self.butten= btn;

    }
    
    if ([self.deleget respondsToSelector:@selector(btnClic:)]) {
        [self.deleget btnClic:btn];
    }else
    {
        NSLog(@"为实现代理");
    }
    
}
@end
